package com.lx.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

//@Configuration  //用于定义配置类，可替换xml配置文件，被注解的类内部包含有一个或多个被@Bean注解的方法
//@PropertySource("classpath:application.properties")  //druid第一种方式注入JDBC
//@EnableConfigurationProperties(JdbcProperties.class)   //druid第二种方式注入
public class JdbcConfig {

/*  方式一
    @Value("${spring.datasource.url}")
    String url;
    @Value("${spring.datasource.driver-class-name}")
    String driver;
    @Value("${spring.datasource.username}")
    String user;
    @Value("${spring.datasource.password}")
    String password;*/

/*
    @Bean
    public DataSource dataSource(JdbcProperties prop){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(prop.getDriver());
        dataSource.setUrl(prop.getUrl());
        dataSource.setUsername(prop.getUser());
        dataSource.setPassword(prop.getPassword());
        return dataSource;
    }*/

//druid第三种注入
/*    @Bean
    @ConfigurationProperties(prefix = "spring")
    public DataSource dataSource() {
        return new DruidDataSource();
    }*/
}
